<?php

/**
 * This is the model class for table "public.tr_m_medic_profile".
 *
 * The followings are the available columns in table 'public.tr_m_medic_profile':
 * @property integer $id
 * @property string $medic_id_hd
 * @property string $profile_id
 * @property string $fill
 * @property integer $sort
 * @property integer $c_b
 * @property string $c_d
 * @property integer $e_b
 * @property string $e_d
 *
 * The followings are the available model relations:
 * @property TrMProfile $profile
 * @property TrMMedic $medicIdHd
 */
class TrMMedicProfile extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'public.tr_m_medic_profile';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('sort, c_b, e_b', 'numerical', 'integerOnly'=>true),
			array('fill', 'length', 'max'=>255),
			array('c_d, e_d', 'length', 'max'=>6),
			array('medic_id_hd, profile_id', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, medic_id_hd, profile_id, fill, sort, c_b, c_d, e_b, e_d', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'profile' => array(self::BELONGS_TO, 'TrMProfile', 'profile_id'),
			'medicIdHd' => array(self::BELONGS_TO, 'TrMMedic', 'medic_id_hd'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'medic_id_hd' => 'Medic Id Hd',
			'profile_id' => 'Profile',
			'fill' => 'Fill',
			'sort' => 'Sort',
			'c_b' => 'C B',
			'c_d' => 'C D',
			'e_b' => 'E B',
			'e_d' => 'E D',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('medic_id_hd',$this->medic_id_hd,true);
		$criteria->compare('profile_id',$this->profile_id,true);
		$criteria->compare('fill',$this->fill,true);
		$criteria->compare('sort',$this->sort);
		$criteria->compare('c_b',$this->c_b);
		$criteria->compare('c_d',$this->c_d,true);
		$criteria->compare('e_b',$this->e_b);
		$criteria->compare('e_d',$this->e_d,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return TrMMedicProfile the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
